import React from "react";
import {withRouter} from "react-router-dom";
import {loginTest} from "@/api/login"
import {connect} from "react-redux";
import {setUserInfo} from "@/redux/user.redux";
import {setToken} from "@/axios/auth";
@connect(
  null,
  {setUserInfo}
)
@withRouter
class CheckLogin extends React.Component{
  componentDidMount() {
    loginTest().then(res=>{
      if(res["code"]!=="0"){
        this.props.history.push('/login');
        return
      }
      let {token,info}=res;
      let userInfo={user:info.user,dynamicRoutes:info.dynamicRoutes,token};
      this.props.setUserInfo(userInfo);
      setToken(token);
    }).catch(err=>{
      this.props.history.push('/login')
    })
  }

  render() {
    return null;
  }

}

export default CheckLogin;
